/*
 * Copyright Iain Sproat, 2008
 * 
 *
 */
using System;
using System.Text;
using System.IO;
using System.Collections.Generic;

using Newtonsoft.Json;
using FreeBase.Fluent;

namespace FreeBase.Fluent.MQLConverter
{

	
	internal static class Helper
	{
		internal static IDictionary<string, IList<FBCriteria>> SeperateCriteriaByProperty( IList<FBCriteria> criteria )
		{
			if( criteria == null )
				throw new ArgumentNullException( "criteria" );
			IDictionary<string, IList<FBCriteria>> seperatedCriteria
				= new Dictionary<string, IList<FBCriteria>>( criteria.Count );
			foreach(FBCriteria crit in criteria)
			{
				if( seperatedCriteria.ContainsKey( crit.PropertyName ) )
					seperatedCriteria[crit.PropertyName].Add( crit );
				else
					seperatedCriteria.Add( crit.PropertyName, new List<FBCriteria>(){crit} );
			}
			return seperatedCriteria;
		}
		
		internal static string SerializeComparisonOperator( FBCriteria crit )
		{
			switch( crit.GetOperator )
			{
				case ComparisonOperator.Is:
					if( crit.JoinType == JoinType.OR )
						return "|=";
					return string.Empty;
				case ComparisonOperator.IsNot:
					return "!=";
				case ComparisonOperator.IsGreaterThan:
					return ">";
				case ComparisonOperator.IsLessThan:
					return "<";
				case ComparisonOperator.IsGreaterOrEqualTo:
					return ">=";
				case ComparisonOperator.IsLessOrEqualTo:
					return "<=";
				case ComparisonOperator.TextualComparison:
					return "~=";
				default:
					return string.Empty;
			}
		}
	}
}
